package client.comm.baoding.adapter.main

import android.content.Context
import android.content.Intent
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.comm.baoding.R
import client.comm.baoding.api.bean.CateGoods
import client.comm.baoding.databinding.ItemGylCateGoodBinding
import client.comm.baoding.ui.GylCateGoodsListActivity
import client.comm.commlib.base.BaseAdapter
import client.comm.commlib.base.BindingViewHoder
import com.bumptech.glide.RequestManager

class GylCateGoodAdapter : BaseAdapter<CateGoods.TypeInfo> {

    fun itemClick(bean: CateGoods.TypeInfo) {
        context.startActivity(Intent(context, GylCateGoodsListActivity::class.java).apply {
            putExtra("title_name", bean.name)
            putExtra("cate_id", bean.category_id)
        })
    }

    val manager: RequestManager

    constructor(context: Context, manager: RequestManager) : super(context) {
        this.manager = manager
    }
    //设置商品label标签

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.item_gyl_cate_good,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as ItemGylCateGoodBinding
        val bean = getItem(position)

        binding.bean = bean
        binding.event = this
       manager.load(bean.small_img).error(R.mipmap.ic_launcher).into(binding.ivGood)
    }

}